﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FilStartUps_Mobile.FILAPI;
using FilStartUps_Mobile.Models;

namespace FilStartUps_Mobile.Controllers
{
    public class ProfileController : Controller
    {
        //
        // GET: /Profile/
        FilStartUpsEntities db_connect = new FilStartUpsEntities();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult MemberProfile()
        {
            try
            {
                var user = db_connect.Members.Where(m => m.emailaddress.Equals(User.Identity.Name)).SingleOrDefault();
                var profile = db_connect.Profiles.Where(p => p.memberidFK.Equals(user.memberidPK)).SingleOrDefault();
                return View(profile);
            }
            catch
            {

            }
            return View();
        }
        [HttpGet]
        public ActionResult EditProfile()
        {
            var user = db_connect.Members.Where(m => m.emailaddress.Equals(User.Identity.Name)).SingleOrDefault();
            var profile = db_connect.Profiles.Where(p => p.memberidFK.Equals(user.memberidPK)).SingleOrDefault();
            return View(profile);
        }

        [HttpPost, ValidateInput(false)]
        public ActionResult EditProfile(Profile profile, HttpPostedFileBase postedFile,
                                FormCollection form)
        {
            return View();
        }

        public ActionResult ProfilePicture(int id)
        {
            try
            {
                var profilepic = db_connect.Profiles.Where(p => p.profileidPK.Equals(id)).SingleOrDefault();
                byte[] image = profilepic.image;
                return File(image, profilepic.imagetype);
            }
            catch
            {
                return null;
            }

        }

    }
}
